< previous page page_711 next page >

Page 711
Using Your Own ActiveX DLL with ASP
You can do a lot by using VBScript code in an Active Server Page, but VBScript of course lacks the power of full-blown Visual Basic, not to mention all of the IDE features you may be used to. However, by using the Server.CreateObject function, you can create instances of your own ActiveX DLL's on an ASP page.
First, create and test your ActiveX DLL in a normal Visual Basic environment. Then, you need to install and register the DLL on the Web server so it can be used from an ASP page. Creating an ActiveX DLL is covered in more detail in Chapter 16, ''Classes: Reusable Components."
sarrow.gifSee "Creating an ActiveX DLL," p. 368
Once you have created your ActiveX DLL, install it on the Web server. If you already have the Visual Basic runtime files installed on the Web server, installation of your DLL may be as simple as copying the DLL over and running REGSVR32 to register it.
After the DLL is installed and registered, you can create an object from a class in the DLL with the Server.CreateObject statement:
Set objVariable = Server.CreateObject("MyProject.MyClass")
After an object has been created, you can access it from the current ASP page. To pass it along to another page, you can store it in a session variable, like the GLOBAL.ASAexample in the previous section.
Using ActiveX DLLs with ASP is very simple, just access the methods and properties from VBScript:
Response.Write objVariable.GetUserData("Smith")
VBScript only uses variants, so be careful when declaring functions in your DLL. Arrays and other data types do not always work the same as they would in standard Visual Basic. You should create a small test function in your DLL so that you will be familiar with the VBScript limitations.
The IIS Application Project
A new project type in Visual Basic 6.0 is the IIS Application. An IIS Application is a special type of ActiveX DLL that works on a Web server to process requests from the client and return HTML to the user's browser. Does this sound similar to what an ASP page does? Well it should. IIS applications allow you to access many of the same objects (Server, Response, Request, and so on ) as an ASP page and are themselves hosted in an ASP page. As a matter of fact, an IIS application works in a similar way to what was covered in the last section regarding calling an ActiveX DLL from an ASP page. The difference is that an IIS Application is set up specifically to deal with the Web; although an ActiveX DLL project contains a standard VB class module, an IIS Application project contains a WebClass.

 
< previous page page_711 next page >